home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / Gnuplot / Source / TicOptionsPanel.m < prev    next >
Encoding:
Text File  |  1993-03-18  |  6.5 KB  |  297 lines

  1.  
  2. static char RCSId[]="$Id: TicOptionsPanel.m,v 1.1.1.1 1993/03/18 03:36:32 davis Exp $";
  3.  
  4.  
  5. #import <appkit/Application.h>
  6. #import <appkit/Button.h>
  7. #import <appkit/Form.h>
  8. #import <appkit/Matrix.h>
  9. #import <appkit/PopUpList.h>
  10. #import <appkit/TextField.h>
  11.  
  12. #import "CellScrollView.h"
  13. #import "GnuplotPlot.h"
  14. #import "Status.h"
  15. #import "StatusTics.h"
  16. #import "TicCell.h"
  17. #import "TicObject.h"
  18. #import "TicOptionsPanel.h"
  19.  
  20.  
  21. @interface TicOptionsPanel (Private)
  22.  
  23. - _updatePanel;            /** Overridden from OptionsPanel (Private) **/
  24.  
  25. @end
  26.  
  27.  
  28. @implementation TicOptionsPanel
  29.  
  30. - init
  31. {
  32.     [super init];
  33.  
  34.     [NXApp loadNibSection: "TicOptionsPanel.nib"
  35.             owner: self
  36.         withNames: NO
  37.          fromZone: [self zone]];
  38.  
  39.     [panel setFrameUsingName:"TicOptionsPanel"];
  40.     [panel setFrameAutosaveName:"TicOptionsPanel"];
  41.  
  42.     /*  Initialize custom tics CellScrollView  */
  43.  
  44.     [userScrollView initMatrix:[TicCell class]];
  45.     userMatrix = [userScrollView cellMatrix];
  46.     [[userMatrix setAction:@selector(selectTic:)] setTarget:self];
  47.     lastCoord = [coordButton tag];
  48.  
  49.     return self;
  50. }
  51.  
  52.  
  53. - changeCoord:sender
  54. {
  55.     [coordButton setTag:[sender selectedTag]];
  56.     [self _updatePanel];
  57.     return self;
  58. }
  59.  
  60.  
  61.  
  62. - doSetTicsType:sender
  63. {
  64.     [status setTicTypeCoord:[[coordButton target] indexOfItem:
  65.                  [coordButton title]] to:[typeMatrix selectedTag]];
  66.     [self _updatePanel];
  67.     return self;
  68. }
  69.  
  70.  
  71. - doSetTicsSeries:sender
  72. {
  73.     int coord = [coordButton tag];
  74.     double start = [startField doubleValue];
  75.     double incr = [incrementField doubleValue];
  76.     double end = [endField doubleValue];
  77.     int index = [sender selectedIndex];
  78.  
  79.     /* 
  80.      *  The increment must take us from the start to the end.  And the 
  81.      *  end must be larger than the start (gnuplot help says this is 
  82.      *  not true, but it doesn't seem to work otherwise).
  83.      */
  84.     if (((start + incr) <= start) || (start >= end))
  85.     [self _updatePanel];
  86.  
  87.     else {
  88.     id selectedCell = [sender selectedCell];
  89.  
  90.     if (selectedCell == startField)
  91.         [status setTicStartCoord:coord to:start];
  92.     else if (selectedCell == incrementField)
  93.         [status setTicIncrementCoord:coord to:incr];
  94.     else
  95.         [status setTicEndCoord:coord to:end];
  96.     }
  97.  
  98.     return self;
  99. }
  100.  
  101.  
  102. - addTic:sender
  103. {
  104.     int coord = [coordButton tag];
  105.     TicObject *ticObject;
  106.     int count;
  107.  
  108.     ticObject = [[TicObject allocFromZone:[status zone]]
  109.                initFromString:[userTitleForm stringValueAt:0]
  110.                   doubleValue:[userValueForm doubleValueAt:0]];
  111.     [ticsList[coord] addObject:ticObject];
  112.     [userScrollView loadCellsFrom:ticsList[coord]];
  113.  
  114.     count = [ticsList[coord] count] - 1;
  115.     [userMatrix scrollCellToVisible:count :0];
  116.     [userMatrix selectCellAt:count:0];
  117.  
  118.     [self selectTic:self];
  119.     [status reportSettingsChange:self];
  120.  
  121.     return self;
  122. }
  123.  
  124.  
  125. - deleteTics:sender
  126. {
  127.     int coord = [coordButton tag];
  128.     int i;
  129.  
  130.     for (i=[userMatrix cellCount]-1; i>=0; i--) {
  131.     TicCell *cell = [userMatrix cellAt:i:0];
  132.     if ([cell isHighlighted]) {
  133.         /*
  134.          *  If a cell is highlighted, remove (and free) the 
  135.          *  corresponding item from the list of TicObjects.
  136.          */
  137.         [[ticsList[coord] removeObject:[cell subObject]] free];
  138.     }
  139.     }
  140.  
  141.     [userScrollView loadCellsFrom:ticsList[coord]];
  142.  
  143.     [userMatrix scrollCellToVisible:0 :0];
  144.     [userMatrix selectCellAt:0:0];
  145.  
  146.     [self selectTic:self];
  147.     [status reportSettingsChange:self];
  148.     return self;
  149. }
  150.  
  151.     
  152. - modifyTic:sender
  153. {
  154.     int coord = [coordButton tag];
  155.     TicCell *cell = [userMatrix selectedCell];
  156.     TicObject *tic = [cell subObject];
  157.  
  158.     [tic setStringValue: [userTitleForm stringValueAt:0]];
  159.     [tic setDoubleValue:[userValueForm doubleValueAt:0]];
  160.     [userScrollView loadCellsFrom:ticsList[coord]];
  161.     [userMatrix selectCell:cell];
  162.  
  163.     [self selectTic:self];
  164.     [status reportSettingsChange:self];
  165.     return self;
  166. }
  167.  
  168.  
  169. /* 
  170.  *  Make other controls in the window reflect the currently selected 
  171.  *  tic.  Assumes that the current tic type is TIC_USER.
  172.  */
  173. - selectTic:sender
  174. {
  175.     TicObject *tic = [[userMatrix selectedCell] subObject];
  176.  
  177.     if (tic) {
  178.     [userTitleForm setStringValue:[tic stringValue] at:0];
  179.     [userValueForm setDoubleValue:[tic doubleValue] at:0];
  180.     } else {
  181.     [userTitleForm setStringValue:"" at:0];
  182.     [userValueForm setStringValue:"" at:0];
  183.     }
  184.  
  185.     [deleteTicButton setEnabled:tic? YES: NO];
  186.     [modifyTicButton setEnabled:tic? YES: NO];
  187.     [userValueForm selectTextAt:0];
  188.  
  189.     return self;
  190. }
  191.  
  192.  
  193. // Shuts up the compiler about unused RCSId
  194. - (const char *) rcsid
  195. {
  196.     return RCSId;
  197. }
  198.  
  199.  
  200. @end
  201.  
  202.  
  203.  
  204.  
  205.  
  206. @implementation TicOptionsPanel (Private)
  207.  
  208.  
  209. - _updatePanel
  210. {
  211.     int coord = [coordButton tag];
  212.     int type = TIC_COMPUTED;
  213.     BOOL isEnabled;
  214.  
  215.     [panel disableDisplay];
  216.  
  217.     /* 
  218.      *  If the current status is not nil, update the values of all the 
  219.      *  controls.
  220.      */
  221.     if (status) {
  222.  
  223.     int i;
  224.     BOOL isThreeD = [status isThreeD];
  225.  
  226.         for (i = 0 ; i < 3 ; i++)            //
  227.             ticsList[i] = [status ticDefsCoord:i];    //
  228.  
  229.     if (!isThreeD && (coord == Z_TAG))  {
  230.         id cell = [[coordButton target] findCellWithTag:X_TAG];
  231.         [coordButton setTitle:[cell title]];
  232.         [coordButton setTag:coord = [cell tag]];
  233.     }
  234.  
  235.     type = [status ticTypeCoord:coord];
  236.     [typeMatrix selectCellWithTag:type];
  237.  
  238.     /* Uniform Range (Series) section */
  239.  
  240.     [startField setDoubleValue:[status ticStartCoord:coord]];
  241.     [incrementField setDoubleValue:[status ticIncrementCoord:coord]];
  242.     [endField setDoubleValue:[status ticEndCoord:coord]];
  243.  
  244.     /* User-Defined Range section */
  245.  
  246.     if ([userMatrix selectedCell])
  247.         [self selectTic:self];
  248.  
  249.     [userScrollView loadCellsFrom:ticsList[coord]];
  250.     lastCoord = coord;
  251.     
  252.     /* 
  253.      *  Enabling/Disabling of the Z coordinate button in the pop 
  254.      *  up list.
  255.      */
  256.     
  257.     [[[coordButton target] findCellWithTag:Z_TAG] setEnabled:isThreeD];
  258.  
  259.     }
  260.  
  261.     /* Now do enabling/disabling */
  262.  
  263.     [typeMatrix setEnabled: isEnabled = (status? YES : NO)];
  264.     [coordButton setEnabled: isEnabled];
  265.  
  266.     [startField setEnabled:isEnabled = ((type == TIC_SERIES) && status)];
  267.     [incrementField setEnabled:isEnabled];
  268.     [endField setEnabled:isEnabled];
  269.  
  270.     [addTicButton setEnabled:isEnabled = ((type == TIC_USER) && status)];
  271.     [userTitleForm setEnabled:isEnabled];
  272.     [userValueForm setEnabled:isEnabled];
  273.     [userMatrix setEnabled:isEnabled];
  274.  
  275.     [deleteTicButton setEnabled:isEnabled = [userMatrix selectedCell]
  276.                         && status];
  277.     [modifyTicButton setEnabled:isEnabled];
  278.  
  279.  
  280.     switch (type) {
  281.     case TIC_USER:
  282.     [userValueForm selectTextAt:0];
  283.     break;
  284.     case TIC_SERIES:
  285.     [seriesForm selectTextAt:0];
  286.     break;
  287.     }
  288.  
  289.     [panel reenableDisplay];
  290.     [panel display];
  291.  
  292.     return self;
  293. }
  294.  
  295.  
  296. @end
  297.